<script>
	let _this;
    
	export default {
		onLaunch: function() {
			// 清除所有的缓存
			// #ifdef MP-WEIXIN
			// wx.clearStorage();
			// wx.clearStorageSync();
			// #endif
            
            const version = wx.getSystemInfoSync().SDKVersion
            console.log('微信版本 -- ',version);
            
			_this = this;
			let desc = '';
			let keyHttpUrl = 'zcsoft_uni_insure_httpurl';
			let keySysCfg = 'zcsoft_uni_insure_sysconfig';
			let wxSysConfig = uni.getStorageSync(keySysCfg);
			let PlateType = '';
			let httpUrl = '';
			// #ifdef MP-WEIXIN

			PlateType = 'WxMP';
			let IsCanSysInfo = uni.canIUse('getSystemInfoSync.return.screenWidth');
			if (IsCanSysInfo) {
				let curSystem = uni.getSystemInfoSync();
				desc += '品牌:' + curSystem.brand;
				desc += ', 型号:' + curSystem.model;
				desc += ', 型号:' + curSystem.model;
				desc += ', 像素比:' + curSystem.pixelRatio;
				desc += ', 屏宽:' + curSystem.screenWidth;

				desc += ', 屏高:' + curSystem.screenHeight;
				desc += ', 系统版本:' + curSystem.system;
				desc += ', 微信版本:' + curSystem.version;
				desc += ', 平台:' + curSystem.platform;
			}
			if (wxSysConfig) {
				wxSysConfig = JSON.parse(wxSysConfig);
				uni.setStorageSync(keyHttpUrl, wxSysConfig.WxMpUrl);
				_this.$ZcPublic.Domain = wxSysConfig.Domain;
				_this.$ZcPublic.Modal = wxSysConfig.Modal;
				_this.$ZcPublic.CarUrl = wxSysConfig.CarUrl;
				_this.$ZcPublic.CarKey = wxSysConfig.CarKey;
			} else {
				uni.setStorageSync(keyHttpUrl, _this.$ZcPublic.Domain + 'UniService/doPageService.ashx');
			}
			httpUrl = uni.getStorageSync(keyHttpUrl);
			if (httpUrl) {
				httpUrl = httpUrl + '?IsNeedLogin=false&dc=' + new Date().getTime();
				uni.request({
					url: httpUrl,
					data: {
						Name: 'Uni_Config',
						Action: 'getConfig',
						Data: {
							Desc: desc
						}
					},
					method: "POST",
					dataType: "json",
					success: function(response) {
						if (response.statusCode === 200) {
							try{
                                console.log('response -- ',response);
								let wxRes = response.data;
								_this.$ZcPublic.Domain = wxRes.data.Domain;
								_this.$ZcPublic.Modal = wxRes.data.Modal;
								_this.$ZcPublic.CarUrl = wxRes.data.CarUrl;
								_this.$ZcPublic.CarKey = wxRes.data.CarKey;
								
                                if(uni.getStorageSync('AppVer') &&  parseInt(uni.getStorageSync('AppVer'))<parseInt(wxRes.data.AppVer)){
                                    if(wxRes.data.ClearAppCache == "true"){
                                        uni.clearStorage();
                                        uni.clearStorageSync();
                                  };
                                }
                                
								let keySysCfg_Val = '{"IsWxDebug":"' + wxRes.data.IsWxDebug + '","CarUrl":"' + wxRes.data.CarUrl +'","CarKey":"' + wxRes.data.CarKey + '","WxMpUrl":"' + wxRes.data.WxMpUrl + '","VueUrl":"' + wxRes.data.VueUrl + '","Domain":"' + wxRes.data.Domain + '","Modal":"' + wxRes.data.Modal + '"}';
								uni.setStorageSync(keySysCfg, keySysCfg_Val);
								let cvtStr = JSON.stringify(wxRes.data);
                                uni.setStorageSync(keyHttpUrl, wxRes.data.WxMpUrl);
                                uni.setStorageSync('key_partner_iswxdebug', wxRes.data.IsWxDebug);
                                uni.setStorageSync('key_partner_voitimes', wxRes.data.VoiTimes);
                                uni.setStorageSync('key_partner_voivibrt', wxRes.data.VoiVibrt);
                                uni.setStorageSync('AppVer', wxRes.data.AppVer);
								
							}catch(e){
								console.log('e',e);
							}

						} else {
							uni.showModal({
								title: '警告',
								content: '网络超时，系统初始化失败!',
								showCancel: false
							});
						}
					},
					fail: function(response) {
						if (response.errMsg) {
							if (response.errMsg.toLowerCase().trim() === 'request:fail') {
								uni.showModal({
									title: '警告',
									content: '已断网，系统初始化失败!',
									showCancel: false
								});
							}
						}
					}
				});
			}
			// #endif

			// #ifdef H5
			PlateType = 'H5';
			if (wxSysConfig) {
				wxSysConfig = JSON.parse(wxSysConfig);
				uni.setStorageSync(keyHttpUrl, wxSysConfig.VueUrl);
				_this.$ZcPublic.Domain = wxSysConfig.Domain;
			} else {
				uni.setStorageSync(keyHttpUrl, _this.$ZcPublic.Domain + 'UniService/doVueService.ashx');
			}
			httpUrl = uni.getStorageSync(keyHttpUrl);
			if (_this.$ZcPublic.Server.IsDebug == true || _this.$ZcPublic.Server.IsDebug == 'true') {
				httpUrl = httpUrl + '?IsDebug=true&IsNeedLogin=false&dc=' + new Date().getTime();
			} else {
				httpUrl = httpUrl + '?IsDebug=false&IsNeedLogin=false&dc=' + new Date().getTime();
			}
			_this.$ZcPublic.Http.post(httpUrl, JSON.stringify({
					Name: 'Uni_Config',
					Action: 'getInitConfig',
					Data: {}
				}), {
					withCredentials: true
				})
				.then(function(response) {
					if (response.status === 200) {
						let wxRes = response.data;
						_this.$ZcPublic.Domain = wxRes.data.Domain;
						_this.$ZcPublic.Modal = wxRes.data.Modal;
						_this.$ZcPublic.CarUrl = wxRes.data.CarUrl;
						_this.$ZcPublic.CarKey = wxRes.data.CarKey;
						console.log('H5:wxRes', response.data);
					} else {
						uni.showModal({
							title: '警告',
							content: '网络超时，系统初始化失败!',
							showCancel: false
						});
					}
				})
				.catch(function(err) {});
			// #endif

			// end
		},
		onShow: function() {},
		onHide: function() {},
		onError: function(err) {
			console.log('onError',err);
			uni.showToast({
				title: err.message,
				position: 'center',
				duration: 3000
			});
		},
		zcShow:function() {
			console.log('过渡动画');
		}
	}
</script>

<style>
	/*每个页面公共css */
	@import './common/uni.css';

	page {
		background: #F5F5F5;
		height: 100%;
		color: #333333;
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		font-size: 28upx !important;
	}

	view {
		font-family: Microsoft YaHei;
	}

	.container {
		width: 100%;
		height: 100%;
	}

	/* view{font-size: 36upx!important;} */
	.zcFlex_row {
		flex-direction: row !important;
	}

	.zcFlex_column {
		flex-direction: column !important;
	}

	.zcJustifyC_center {
		justify-content: center !important;
	}

	.zcJustifyC_end {
		justify-content: flex-end !important;
	}

	.zcJustifyC_between {
		justify-content: space-between !important;
	}

	.zcJustifyC_start {
		justify-content: flex-start !important;
	}

	.zcAlignC_center {
		align-content: center !important;
	}

	.zcAlignC_end {
		align-content: flex-end !important;
	}

	.zcAlignC_between {
		align-content: space-between !important;
	}

	.zcAlignC_around {
		align-content: space-around !important;
	}

	.zcAlignI_center {
		align-items: center !important;
	}

	.zcAlignI_end {
		align-items: flex-end !important;
	}

	.zcAlignI_start {
		align-items: flex-start !important;
	}

	.zcFlex1 {
		flex: 1 !important;
	}

	.zcOverflow3 {
		text-overflow: ellipsis;
		overflow: hidden;
		white-space: nowrap;
	}

	.zcRelative {
		position: relative;
	}

	
    @font-face {
      font-family: 'iconfont';  /* project id 1144889 */
      src: url('//at.alicdn.com/t/font_1144889_wtj7f0jkzki.ttf') format('truetype');
    }
	
	.iconfont {
		font-family: "iconfont" !important;
		font-size: 28upx;
		font-style: normal;
		position: relative;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
	}
	.icon-qiandai:before {//钱袋
	  content: "\e614";
	}
	.icon-bianji1:before { //编辑
	  content: "\e615";
	}
	.icon-file:before { //文本
	  content: "\e6d3";
	}
	.icon-jinbiyue:before { //金币$
	  content: "\e612";
	}
	.icon-shijian:before { //时间
	  content: "\e647";
	}
	.icon-icons-:before { //线索
	  content: "\e6b9";
	}
	.icon-zhengque:before { //成功
	  content: "\e627";
	}
	.icon-shibai1:before { //失败
	  content: "\e660";
	}

	.uni-icon-search:before{font-weight: bold;}
	.icon-xialasanjiao:before{
		content: "\e629";
	}

	.icon-unie6a3:after {
		content: "\e66d";
	}

	.icon-bianji:before {
		content: "\e60e";
	}

	.icon-calendar:before {
		content: "\e609";
	}

	.icon-unie6a42:before {
		content: "\e66e";
	}

	.icon-sanjiaojiantoutriangular-copy:before {
		content: "\e600";
		font-weight: bold;
		padding-left: 40upx;
		line-height: 2;
	}

	.icon-zhongguorenbao:before {
		content: "\e610";
		font-size: 60upx;
	}

	.icon-zhongyinbaoxian:before {
		content: "\e7eb";
		font-size: 60upx;
	}

	.icon-zhongguopingan:before {
		content: "\e60f";
		font-size: 60upx;
	}

	.icon-xinzeng:before {
		content: "\e6a3";
	}
	
	.icon-shaixuan:before {
		content: "\e674";
	}

	.icon-shaixuan-af:after {
		content: "\e674";
	}

	.icon-biaoqian1:before {
		content: "\e613";
		/* transform: rotate(90deg); */
	}
	.icon-dian:before{
		content: '\e608';
	}
    .icon-shuaxin:before{
        content: '\e63f';
    }
	
	button:after{
		border: none !important;
	}
	image{height: auto;}
	.uni-tab-bar-loading{margin-bottom: 104upx;}
      /* 自定义 picker 默认提示文本样式 */  
    .placeholder{color: #BEBEBE !important;font-weight: 400;}
</style>
